package com.whc.pay.controller;

import com.whc.api.dto.PayApplyDTO;
import com.whc.common.domain.Result;

import com.whc.pay.domain.entity.PayOrder;
import com.whc.pay.service.IPayOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "支付相关接口")
@RestController
@RequestMapping("/client/pay")
//@RequiredArgsConstructor
@Slf4j
public class PayController {
    @Autowired
    private IPayOrderService payOrderService;

    @ApiOperation("生成支付订单")
    @PostMapping("/addPay")
    public Result addPay(@RequestBody PayApplyDTO payApplyDTO){
        payOrderService.addPay(payApplyDTO);


        return Result.success();
    }
    @ApiOperation("删除支付订单")
    @DeleteMapping("/deletePay")
    public Result deletePay(@RequestParam("payId") Long payId){
        payOrderService.deletePay(payId);
        return Result.success();
    }
    @ApiOperation("查询支付单根据订单编号")
    @GetMapping("/selectPayIdByOrderNumber")
    public Result<Long> selectPayByOrderId(@RequestParam("orderNumber") Long orderNumber){
        PayOrder payOrder = payOrderService.selectByOrderId(orderNumber);
        return Result.success(payOrder.getId());
    }
    @ApiOperation("修改订单为已支付")
    @PutMapping("/toPay")
    public Result toPay(@RequestParam("payId") Long payId){
        payOrderService.toPay(payId);
        return Result.success();
    }
}
